package com.jmyd.coupon.server.domain.vo;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.jmyd.commons.annatations.Date2LongSerializer;
import com.jmyd.coupon.server.domain.po.SceneActivity;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户活动对象
 */
@Data
public class SceneActivityVo {

    /**
     * 活动ID
     */
    private Long id;

    /**
     * 活动标题
     */
    private String title;

    /**
     * 活动图片地址
     */
    private String imageUrl;

    /**
     * 活动h5页面地址
     */
    private String pageUrl;

    /**
     * 绑定优惠券
     */
    private Long moduleId;

    /**
     * 是否展示活动
     */
    private Integer visible;

    /**
     * 活动有效期开始时间
     */
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date validStartTime;

    /**
     * 活动有效期结束时间
     */
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date validEndTime;

    public SceneActivityVo build(SceneActivity po) {
        SceneActivityVo vo = new SceneActivityVo();
        BeanUtils.copyProperties(po, vo);
        return vo;
    }

    public List<SceneActivityVo> buildVoList(List<SceneActivity> poList) {
        if (CollectionUtils.isEmpty(poList)) {
            return new ArrayList<>(1);
        }
        return poList.stream().map(this::build).collect(Collectors.toList());
    }
}
